package com.mark.enums;

/**
 * Created by Mark on 2018/3/24.
 * 用户模块的枚举类
 */
public enum UserStateEnum {
    SUCCESS(0,"SUCCESS"),
    ERROR(1,"ERROR"),
    NEED_LOGIN(10,"NEED_LOGIN"),
    ILLEGAL_ARGUMENT(2,"ILLEGAL_ARGUMENT"),
    CURRENT_USER(3,"currentUser"),

    /*用户身份*/
    ROLE_CUSTOMER(1),//普通用户
    SELLER_CUSTOMER(2),//店家

    USERNAME("username"),
    EMAIL("email");

    private int state;
    private String stateInfo;
    private String type;
    private int role;

    //注意：枚举中的构造函数需要声明private
    UserStateEnum(int state, String stateInfo) {
        this.state = state;
        this.stateInfo = stateInfo;
    }
    UserStateEnum(String type) {
        this.type = type;
    }

    UserStateEnum(int role) {
        this.role = role;
    }

    /**
     * 依据传入的state返回相应的enum值
     */
    public static UserStateEnum stateOf(int state) {
        for (UserStateEnum stateEnum : values()) {
            if (stateEnum.getState() == state) {
                return stateEnum;
            }
        }
        return null;
    }

    public int getState() {
        return state;
    }

    public String getStateInfo() {
        return stateInfo;
    }

    public String getType() {
        return type;
    }

    public int getRole() {
        return role;
    }
}
